﻿using System;
using GeoAPI.Operation.Buffer;

namespace NetTopologySuite.Operation.Buffer
{
	public class BufferParameters : IBufferParameters
	{
		public BufferParameters()
		{
		}

		public BufferParameters(int quadrantSegments)
		{
			this.QuadrantSegments = quadrantSegments;
		}

		public BufferParameters(int quadrantSegments, EndCapStyle endCapStyle) : this(quadrantSegments)
		{
			this.EndCapStyle = endCapStyle;
		}

		public BufferParameters(int quadrantSegments, EndCapStyle endCapStyle, JoinStyle joinStyle, double mitreLimit) : this(quadrantSegments, endCapStyle)
		{
			this.JoinStyle = joinStyle;
			this.MitreLimit = mitreLimit;
		}

		public int QuadrantSegments
		{
			get
			{
				return this._quadrantSegments;
			}
			set
			{
				this._quadrantSegments = value;
				if (this._quadrantSegments == 0)
				{
					this._joinStyle = JoinStyle.Bevel;
				}
				if (this._quadrantSegments < 0)
				{
					this._joinStyle = JoinStyle.Mitre;
					this._mitreLimit = (double)System.Math.Abs(this._quadrantSegments);
				}
				if (value <= 0)
				{
					this._quadrantSegments = 1;
				}
				if (this._joinStyle != JoinStyle.Round)
				{
					this._quadrantSegments = 8;
				}
			}
		}

		public static double BufferDistanceError(int quadSegs)
		{
			double num = System.Math.PI*.5 / (double)quadSegs;
			return 1.0 - Math.Cos(num / 2.0);
		}

		public EndCapStyle EndCapStyle
		{
			get
			{
				return this._endCapStyle;
			}
			set
			{
				this._endCapStyle = value;
			}
		}

		public JoinStyle JoinStyle
		{
			get
			{
				return this._joinStyle;
			}
			set
			{
				this._joinStyle = value;
			}
		}

		public double MitreLimit
		{
			get
			{
				return this._mitreLimit;
			}
			set
			{
				this._mitreLimit = value;
			}
		}

		public bool IsSingleSided { get; set; }

		public double SimplifyFactor
		{
			get
			{
				return this._simplifyFactor;
			}
			set
			{
				this._simplifyFactor = ((value < 0.0) ? 0.0 : value);
			}
		}

		public const int DefaultQuadrantSegments = 8;

		public const double DefaultMitreLimit = 5.0;

		public const double DefaultSimplifyFactor = 0.01;

		private int _quadrantSegments = 8;

		private EndCapStyle _endCapStyle = EndCapStyle.Round;

		private JoinStyle _joinStyle = JoinStyle.Round;

		private double _mitreLimit = 5.0;

		private double _simplifyFactor = 0.01;
	}
}
